<xsl:stylesheet version="1.0" exclude-prefixes="xsl" xmlns:x="http://www.xopus.com/xmlns/config" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output encoding="us-ascii" method="html" version="1.0"
        doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
        doctype-system="http://www.w3.org/TR/html4/loose.dtd" />

  <xsl:param name="q" select="''"/>
  <xsl:param name="element-name" select="''"/>

  <xsl:template match="content-reference">
    <html>
      <head>
        <title>Content Reference Lookup</title>
        <link rel="stylesheet" type="text/css" href="ui/example-app.css"/>
      </head>
      <body onload="lookup.initConref()" class="lookup-ui-dialog">
        <p>Choose a reference from the <xsl:choose>
          <xsl:when test="$q = ''"><xsl:text>collection</xsl:text></xsl:when>
          <xsl:otherwise><a href="lookup-conrefs.php">collection</a></xsl:otherwise>
        </xsl:choose>, or 
          <span>
            <form method="get" action="lookup-conrefs.php" class="lookup-ui-form" id="searchform">
              <input type="hidden" name="element-name" id="elname" value="{$element-name}"/>
              <input type="text" name="q" value="{$q}"/>
              <button type="submit">search</button>
            </form>
          </span> for a specific reference.
        </p>
        
        <div>
          <strong>
            <xsl:variable name="num_references">
              <xsl:choose>
                <xsl:when test="$q = ''">
                  <xsl:value-of select="count(reference[@element-name = $element-name])"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="count(reference[@element-name = $element-name and contains(.,$q)])"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:value-of select="$num_references"/>
            <xsl:text> references found</xsl:text>
            <xsl:if test="$num_references > number(0)">
              <xsl:text>: </xsl:text>
            </xsl:if>
          </strong>
        </div>

         <ul id="items">
           <xsl:choose>
             <xsl:when test="$q = ''">
               <xsl:apply-templates select="reference[@element-name = $element-name]"/>
             </xsl:when>
             <xsl:otherwise>
               <xsl:apply-templates select="reference[@element-name = $element-name and contains(.,$q)]"/>
             </xsl:otherwise>
           </xsl:choose>
        </ul>
        <script type="text/javascript" src="ui/example-app.js"></script>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="reference">
    <li class="reference">
      <a href="{@href}" value="{@href}" id="{@href}" onclick="return lookup.chooseConref(this.getAttribute('value'));">
        <xsl:value-of select="@href"/>
      </a>
    </li>
  </xsl:template>  
</xsl:stylesheet>
